package com.yuanrui.auth.domain.service.impl;

import com.yuanrui.auth.basic.entity.AuthRolePermission;
import com.yuanrui.auth.basic.service.AuthRolePermissionService;
import com.yuanrui.auth.common.enums.IsDeletedFlagEnum;
import com.yuanrui.auth.domain.entity.AuthRolePermissionBO;
import com.yuanrui.auth.domain.service.AuthRolePermissionDomainService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;

@Service
public class AuthRolePermissionDomainServiceImpl implements AuthRolePermissionDomainService {

    @Resource
    private AuthRolePermissionService authRolePermissionService;

    @Override
    public Boolean addRolePermission(AuthRolePermissionBO authRolePermissionBO) {
//        AuthRolePermission authRolePermission = AuthRolePermissionConverter.INSTANCE.convertToEntity(authRolePermissionBO);
//        authRolePermission.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
//        int insert = authRolePermissionService.insert(authRolePermission);
        List<AuthRolePermission> rolePermissions = new LinkedList<>();
        //获取角色id
        Long roleId = authRolePermissionBO.getRoleId();
        //获取权限id列表
        authRolePermissionBO.getPermissionIdList().forEach(permissionId -> {
            AuthRolePermission authRolePermission = new AuthRolePermission();
            authRolePermission.setRoleId(roleId);
            authRolePermission.setPermissionId(permissionId);
            authRolePermission.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
            rolePermissions.add(authRolePermission);
        });
        int insert = authRolePermissionService.insertBatch(rolePermissions);
        return insert > 0;
    }

    @Override
    public Boolean updateRolePermission(AuthRolePermissionBO authRolePermissionBO) {
        return null;
    }

    @Override
    public Boolean deleteRolePermission(AuthRolePermissionBO authRolePermissionBO) {
        return null;
    }
}
